* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 0px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    box-sizing: border-box;
}

.container {
    width: 90%;
    max-width: 1200px;
    margin: 15px;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    /* Usa calc para ocupar quase toda a altura disponível */
    height: calc(100vh - 100px);
    min-height: 500px;
    display: flex;
    flex-direction: column;
}

.header {
    background: #2c3e50;
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header h1 {
    font-size: 1.4em;
    flex-shrink: 1;
}

.status {
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85em;
    background: #e74c3c;
    white-space: nowrap;
}

.status.connected {
    background: #27ae60;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 0; /* importante para scroll funcionar dentro de flexbox */
}

.messages {
    display: flex;
    flex-direction: column;
}

.message {
    margin-bottom: 15px;
    padding: 15px;
    border-radius: 10px;
    max-width: 85%;
    word-wrap: break-word;
}

.message.user {
    background: #3498db;
    color: white;
    margin-left: auto;
    text-align: right;
}

.message.assistant {
    background: #ecf0f1;
    color: #2c3e50;
}

.message.error {
    background: #e74c3c;
    color: white;
}

.input-container {
    padding: 15px 20px;
    background: #f8f9fa;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.button-container {
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 15px;
    border: 2px solid #ddd;
    border-radius: 10px;
    resize: vertical;
    font-size: 14px;
    font-family: inherit;
    min-height: 50px;
    max-height: 150px;
}

#messageInput:focus {
    outline: none;
    border-color: #3498db;
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

#sendButton {
    background: #27ae60;
    color: white;
}

#sendButton:hover {
    background: #229954;
}

#sendButton:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

#clearButton {
    background: #e74c3c;
    color: white;
}

#clearButton:hover {
    background: #c0392b;
}

.btn-falar {
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
    background: #34495e;
    color: white;
}

.btn-falar:hover {
    background: #4a6278;
}

.settings {
    padding: 12px 20px;
    background: #34495e;
    color: white;
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.settings label {
    font-weight: bold;
    font-size: 0.9em;
}

.settings input {
    flex: 1;
    min-width: 150px;
    max-width: 350px;
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    background: white;
    color: #2c3e50;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

main {
    flex-grow: 1;
    width: 100%;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
}

footer {
    background-color: #426499;
    color: #ffffff;
    text-align: center;
    padding: 0.8rem 0;
    margin-top: auto;
    width: 100%;
    font-size: 0.9em;
}

.cor-link-rodape {
    color: #ffffff;
}

.cor-nome-dev-rodape {
    color: #cccccc;
}

.texto-rodape {
    font-size: 100%;
    text-align: left;
}

/* ========== TABLET (601px - 1024px) ========== */
@media (min-width: 601px) and (max-width: 1024px) {
    .container {
        width: 95%;
        height: calc(100vh - 90px);
    }

    .header h1 {
        font-size: 1.2em;
    }

    .settings input {
        max-width: 250px;
    }
}

/* ========== MOBILE (até 600px) ========== */
@media (max-width: 600px) {
    .container {
        width: 100%;
        height: calc(100vh - 60px);
        margin: 0;
        border-radius: 0;
    }

    .header {
        padding: 10px 15px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header h1 {
        font-size: 1em;
        width: 100%;
        text-align: center;
        order: -1;
    }

    .status {
        font-size: 0.75em;
        padding: 4px 10px;
    }

    .btn-falar {
        padding: 6px 12px;
        font-size: 0.85em;
    }

    .chat-container {
        padding: 15px;
    }

    .message {
        max-width: 90%;
        padding: 12px;
    }

    .input-container {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 15px;
    }

    #messageInput {
        width: 100%;
        min-height: 70px;
    }

    .button-container {
        display: flex;
        gap: 10px;
        justify-content: space-between;
    }

    #sendButton,
    #clearButton {
        flex: 1;
        padding: 12px;
        font-size: 15px;
    }

    .settings {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px 15px;
    }

    .settings label {
        font-size: 0.85em;
    }

    .settings input {
        width: 100%;
        max-width: none;
    }

    footer {
        padding: 0.6rem 0;
        font-size: 0.8em;
    }
}

/* ========== TELA GRANDE (1400px+) ========== */
@media (min-width: 1400px) {
    .container {
        max-width: 1400px;
        height: calc(100vh - 80px);
    }

    .header h1 {
        font-size: 1.6em;
    }

    .message {
        max-width: 70%;
    }

    #messageInput {
        font-size: 16px;
    }
}

/* ========== BLOCOS DE CÓDIGO ========== */
.code-block {
    position: relative;
    margin: 10px 0;
    border-radius: 10px;
    overflow: hidden;
    background: #1e1e1e;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: linear-gradient(135deg, #2d2d2d 0%, #1a1a1a 100%);
    color: #888;
    font-size: 0.75em;
    font-family: 'Consolas', 'Monaco', monospace;
    border-bottom: 1px solid #3a3a3a;
}

.code-header .language {
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 1px;
    color: #27ae60;
    background: rgba(39, 174, 96, 0.1);
    padding: 4px 10px;
    border-radius: 4px;
}

.copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.copy-btn:hover {
    background: linear-gradient(135deg, #2980b9 0%, #1f6dad 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.copy-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(52, 152, 219, 0.3);
}

.copy-btn.copied {
    background: linear-gradient(135deg, #27ae60 0%, #1e8449 100%);
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.4);
}

.copy-btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

.code-block pre {
    margin: 0;
    padding: 18px 20px;
    overflow-x: auto;
    background: #1e1e1e;
}

.code-block code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9em;
    color: #d4d4d4;
    line-height: 1.6;
    white-space: pre;
}

/* Código inline (não bloco) */
.message code:not(.code-block code) {
    background: #e8e8e8;
    color: #c7254e;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.88em;
    font-weight: 500;
}

.message.assistant code:not(.code-block code) {
    background: #d5dce4;
}

/* ========== RESPONSIVO PARA BLOCOS DE CÓDIGO ========== */
@media (max-width: 600px) {
    .code-header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .code-header .language {
        font-size: 0.7em;
        padding: 3px 8px;
    }

    .copy-btn {
        padding: 6px 12px;
        font-size: 0.8em;
    }

    .copy-btn svg {
        width: 14px;
        height: 14px;
    }

    .code-block pre {
        padding: 14px 12px;
    }

    .code-block code {
        font-size: 0.82em;
    }
}

/* ========== SELECT DE VOZ ========== */
.voice-select {
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #8e44ad 0%, #9b59b6 100%);
    color: white;
    font-size: 0.9em;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(142, 68, 173, 0.3);
}

.voice-select:hover {
    background: linear-gradient(135deg, #7d3c98 0%, #8e44ad 100%);
    transform: translateY(-1px);
}

.voice-select:focus {
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.4);
}

.voice-select option {
    background: #2c3e50;
    color: white;
    padding: 8px;
}

/* Mobile */
@media (max-width: 600px) {
    .voice-select {
        padding: 6px 10px;
        font-size: 0.8em;
    }
}